package client;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.concurrent.ScheduledFuture;

public class MapleCoolDownValueHolder {

    public final int skillId;
    public final long startTime;
    public final long length;
    public ScheduledFuture scheduledFuture;

    @JsonCreator
    public MapleCoolDownValueHolder(@JsonProperty("skillId") int skillId, @JsonProperty("startTime") long startTime, @JsonProperty("length") long length, @JsonProperty("scheduledFuture") ScheduledFuture scheduledFuture) {
        super();
        this.skillId = skillId;
        this.startTime = startTime;
        this.length = length;
        this.scheduledFuture = scheduledFuture;
    }

    public int getLimitTime() {
        return Math.max(0, (int) (length - (System.currentTimeMillis() - startTime)));
    }

    public void cancel() {
        if (scheduledFuture != null) {
            scheduledFuture.cancel(true);
            scheduledFuture = null;
        }
    }
}
